package com.thrc.borrow.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thrc.borrow.dao.SystemBillDao;
import com.thrc.borrow.entity.SystemBill;
import com.thrc.borrow.vo.SystemBillVo;

@Service
public class SystemBillService implements BaseService<SystemBill, SystemBillVo> {
	@Autowired
	private SystemBillDao systemBillDao;

	@Override
	public SystemBillVo selectById(SystemBill t) {
		return systemBillDao.selectById(t);
	}

	@Override
	public List<SystemBillVo> selectAll(SystemBill t) {
		return systemBillDao.selectAll(t);
	}

	@Override
	public int selectCount(SystemBill t) {
		return systemBillDao.selectCount(t);
	}

	@Override
	public List<SystemBillVo> selectByPage(SystemBill t) {
		t.setStartRow(t.getPageIndex(), t.getPageSize());
		return systemBillDao.selectAll(t);
	}

	@Override
	public void update(SystemBill t) {
		systemBillDao.update(t);
	}

	@Override
	public void delete(SystemBill t) {
		systemBillDao.delete(t);
	}

	@Override
	public void insert(SystemBill t) {
		t.setCreateTime(new Date());
		systemBillDao.insert(t);
	}

	/**
	 * 系统入账
	 * 
	 * @param code
	 *            第三方流水号（非必填）
	 * @param typeInfo
	 *            操作类型
	 * @param money
	 *            金额
	 * @param remark
	 *            备注
	 */
	public void inMoney(String code, String typeInfo, double money, String remark) {
		SystemBill t = new SystemBill();
		t.setCode(code);
		t.setType("入账");
		t.setTypeInfo(typeInfo);
		t.setMoney(money);
		t.setRemark(remark);
		this.insert(t);
	}

	/**
	 * 系统出账
	 * 
	 * @param code
	 *            第三方流水号（非必填）
	 * @param typeInfo
	 *            操作类型
	 * @param money
	 *            金额
	 * @param remark
	 *            备注
	 */
	public void outMoney(String code, String typeInfo, double money, String remark) {
		SystemBill t = new SystemBill();
		t.setCode(code);
		t.setType("出账");
		t.setTypeInfo(typeInfo);
		t.setMoney(money);
		t.setRemark(remark);
		this.insert(t);
	}
}
